package com.zxx.pattern.prototypePattern.prototype;

import java.util.HashMap;
import java.util.Map;

/**
 * 3.创建一个类，从数据库获取实体类，并把它们存储在一个 Hashtable 中。
 * @author zxx on 2020/12/18
 */
public class ShapeCache {

    private Map<String, Shape> shapes;

    public ShapeCache() {
        loadCache();
    }

    private void loadCache() {
        shapes = new HashMap<>();
        shapes.put("circle", new Circle());
        shapes.put("rectangle", new Rectangle());
        shapes.put("triangle", new Triangle());
    }

    public Shape getShape(String id) {
        Shape shape = shapes.get(id);
        return (Shape) shape.clone();
    }


}
